package cre.sample.test.lock;

/**
 * Created by CreGu on 2016/6/21.
 */
public class WaitTest1 {
    static Object obj=new Object();
    public static void main(String[] args) {
        Thread mainThread = Thread.currentThread();
        OtherThread oo = new OtherThread();
        Thread ot = new Thread(oo);

        System.out.println(oo);
        synchronized (oo) {
            System.out.println(mainThread + "wait");
            try {
                ot.start();
                oo.wait();
                System.out.println(mainThread+"continue");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    static class OtherThread implements Runnable{

        @Override
        public void run() {
            System.out.println(this);
            synchronized (this) {
                System.out.println(Thread.currentThread()+"notify");
                this.notify();
                try {
                    Thread.sleep(3000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}